package file

import (
	"fmt"
	. "husd.com/framework/v0/collection"
	"io/ioutil"
	"os"
)

//递归遍历文件夹的下的目录
func walk1(name string) {

	exist := Exists(name)
	if !exist {
		panic("文件或者目录不存在，请检查 " + name)
	}
	stackString := DefaultStack{}
	stackString.Init()
	stackString.Push(name)
	pathSep := string(os.PathSeparator)
	for !stackString.IsEmpty() {
		e := stackString.Pop()
		path := fmt.Sprintf("%v", e)
		//1 判断是文件或者目录
		isDir := IsDir(path)
		if isDir {
			//目录,列出目录下的所有的文件
			items, err := ioutil.ReadDir(path)
			if err != nil {
				panic("读取目录错误，请检查 " + path)
			}
			for _, f := range items {
				stackString.Push(path + pathSep + f.Name())
			}
		} else {
			fmt.Println("file is :" + path)
		}
	}
}
